﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BusinessLogic.Controller;
using DataAccess;
using System.Web;
using DataEntity;

namespace BusinessLogic.Helper
{
    public class LoginHelper
    {
        public bool IsLoggedIn
        {
            get
            {
                if (HttpContext.Current.Session["LoginUserID"] != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }
        public Guid LoginID
        {
            get
            {
                if (IsLoggedIn)
                {
                    return new Guid(HttpContext.Current.Session["LoginUserID"].ToString());
                }
                else
                {
                    return Guid.Empty;
                }
            }
        }
        public string LoginedUserName
        {
            get
            {
                if (IsLoggedIn)
                {
                    return HttpContext.Current.Session["UserName"].ToString();
                }
                else
                {
                    return "";
                }
            }
        }
        public static void Logout()
        {
            HttpContext.Current.Session.RemoveAll();
        }
        public static bool ValidateUser(string email, string password)
        {
            LoginUser validated= new DataProvider().ValidateUser(email, password);
            if (validated != null)
            {
                HttpContext.Current.Session["LoginUserID"] = validated.LoginID;
                HttpContext.Current.Session["UserName"] = validated.Username;
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}
